import { _decorator, EditBox, Label } from "cc";
import { BaseView } from "../../base/BaseView";
import { createRoleMod } from "./CreateRoleMod";
import { EventId } from "../../com/EventMgr";
import { layerMgr } from "../../com/LayerMgr";
import { popupMgr } from "../../com/PopupMgr";
import { ScrollList } from "../../comp/ScrollList";
import { Views } from "../../cfg/XlsxDef";
import { Xlsx, XlsxVo } from "../../cfg/Xlsx";
const { ccclass, property } = _decorator;

/**
 * 创角页
 */
@ccclass("CreateRoleView")
export class CreateRoleView extends BaseView {

    @property(ScrollList)
    careerList: ScrollList<XlsxVo.career>;
    @property(Label)
    labDesc: Label;
    @property(EditBox)
    editName: EditBox;

    onLoad() {
        this.careerList.selectCallback = this.updateView.bind(this);
    }

    protected onOpen(): void {
        // this.on(EventId.reloadXlsx, data => data[Xlsx.career.$name] && this.updateView());
        layerMgr.close(Views.LoginView);
        this.careerList.list = Xlsx.career.vos;
        this.careerList.setSelectedIdx(0);
    }

    protected offListeners(): void {

    }

    protected onClose(): void {

    }

    updateView() {
        let cfg = this.careerList.selection;
        this.labDesc.string = cfg.desc;
    }

    onClickCreate() {
        let name = this.editName.string;
        if (!name) return popupMgr.showFloatText("请输入你的角色名称");
        createRoleMod.tosCreateRole(name, this.careerList.selection.id);
    }

}